﻿<%
'
' 底层函数，外部不要直接引用
' 要求：低耦合
' 函数命名：hu_myNameIsHu

'日期差距
'	@参数 d
' 		Day  d 日
' 		DayOfYear  y 日
' 		Hour  h 小时
' 		Minute  n  分钟
' 		Month  m 月
' 		Quarter  q  季度
' 		Second  s 秒钟
' 		Weekday  w 周
' 		WeekOfYear  ww  日历周
' 		Year  yyyy 年
Function hu_dateDiff(day, d)
	day = Trim(day)
	If Not isDate(day) Then Exit Function
	hu_dateDiff = DateDiff(d,time_date,Cdate(day))
End Function
'生成图片
Function hu_image(src, alt, title, ex)
	hu_image = "<img src="""&src&""" title="""&title&""" alt="""&alt&""" "&ex&"/>"
End Function
'生成链接
Function hu_anchor(src, name, title, ex)
	hu_anchor = "<a href="""&src&""" title="""&title&""" "&ex&">"&name&"</a>"
End Function
'改写IsNull
Function hu_isNull(str)
	hu_isNull = False
	Select Case VarType(str)
	Case vbEmpty, vbNull
		hu_isNull = True : Exit Function
	Case vbString
		If str="" Then hu_isNull = True : Exit Function
	Case vbObject
		If TypeName(str)="Nothing" Or TypeName(str)="Empty" Then hu_isNull = True : Exit Function
	Case vbArray,8194,8204,8209
		If Ubound(str)=-1 Then hu_isNull = True : Exit Function
	End Select
End Function
'格式化时间
Function hu_dateFormat(str, style)
	If Not IsDate(str) Then Exit Function
	Dim tmp
	tmp = style
	tmp = Replace(tmp, "y", Year(str), 1, -1, 1)
	tmp = Replace(tmp, "m", Month(str), 1, -1, 1)
	tmp = Replace(tmp, "d", Day(str), 1, -1, 1)
	tmp = Replace(tmp, "h", Right("0"&Hour(str),2), 1, -1, 1)
	tmp = Replace(tmp, "i", Right("0"&Minute(str),2), 1, -1, 1)
	tmp = Replace(tmp, "s", Right("0"&Second(str),2), 1, -1, 1)
	hu_dateFormat = tmp
End Function
'字符过滤函数
Function hu_changeWord(str, badStandard, changedWord)
	Dim s,i
	s=split(badStandard,",")
	For i=Lbound(s) To ubound(s)
	str=replace(str,s(i),changedWord)
	Next
	hu_changeWord=str
End Function
'替换bug字符 - 展现
Function hu_forShow(str)
	If hu_isNull(str) Then Exit Function
	str=hu_decode(str)
	str=Replace(str,"&#","_74_asp_")
	str=Replace(str,"&amp;","_74_amp_")
	str=Replace(str,"&","&amp;")
	str=Replace(str,"_74_amp_","&amp;")
	str=Replace(str,"<","&lt;")
	str=Replace(str,">","&gt;")
	str=Replace(str,"'","&apos;")
	str=Replace(str,"""","&quot;")
	str=Replace(str,"_74_asp_","&#")
	If hu_style Then hu_forShow=str:Exit Function
	str=Replace(str,"$$","_74_my_")
	str=Replace(str,"$","$$")
	str=Replace(str,"_74_my_","$$")
	hu_forShow=str
End Function
'符号写入数据库
Function hu_common(str)
	If hu_isNull(str) Then Exit Function
	str=Replace(str,"'","&#39;")
	str=Replace(str,vbnewline,"\\")
	str=Replace(str,VbCrLf,"\\")
	hu_common=str
End Function
'过滤用户数据
Function hu_encode(str)
	If hu_isNull(str) Then Exit Function
	str=Replace(str,"74hu_","_74_hu_",1,-1,1)'数据库表前缀替换
	str=Replace(str,"法轮","[滤]")'国内服务器拒绝写入
	hu_encode=str
End Function
'还原用户数据
Function hu_decode(str)
	If hu_isNull(str) Then Exit Function
	str=Replace(str,"_74_hu_","74hu_")
	hu_decode=str
End Function
'用于搜索,登陆过滤等
Function hu_filter(str)
	If hu_isNull(str) Then Exit Function
	str=Replace(str,"'","",1,-1,1)
	str=Replace(str,"74hu_","",1,-1,1)
	str=Replace(str,"法轮","")'国内服务器拒绝写入
	hu_filter=str
End Function
'改写left
Function hu_left(str, strlen)
	If hu_isNull(str) Then hu_left = "":Exit Function
	Dim t, c, i, strTemp
	str = Replace(Replace(Replace(Replace(Replace(str,"&nbsp;"," "),"&quot;",Chr(34)),"&gt;",">"),"&lt;","<"),"&apos;","'")
	t = 0
	strTemp = str
	strlen = CLng(strlen)
	For i = 1 To Len(str)
		c = Abs(Asc(Mid(str, i, 1)))
		If c = 1 Then
			t = t + 1
		Else
			t = t + 0.6'这里的0.6可酌情修改，考虑字符占位不同
		End If
		If t >= strlen Then strTemp = Left(str, i):Exit For
	Next
	If strTemp <> str Then strTemp = strTemp & ".."
	hu_left = Replace(Replace(Replace(Replace(strTemp,"'","&apos;"),Chr(34),""""),">","&gt;"),"<","&lt;")
End Function
'产生随机字母数字
Function hu_randomize()
	Dim c_,id_,tmp_,i_,len_
	randomize
	c_="a,A,1,b,B,2,c,C,3,d,D,4,e,E,5,f,F,6,g,G,7,h,H,8,i,I,9,j,J,0,k,K,l,L,m,M,n,N,o,O,p,P,q,Q,r,R,s,S,t,T,u,U,v,V,w,W,x,X,y,Y,z,Z"
	id_=split(c_,",")
	len_=UBound(id_)+1
	for i_=1 to 10
		tmp_=id_(int(rnd()*len_))&tmp_
	Next
	hu_randomize=tmp_
End Function
'判断字符串是否全英文
Function hu_isLetters(str)
	Dim lstr,i,t_
	If hu_isNull(str) Then hu_isLetters = False:Exit Function
	lstr = LCase(str)
	For i = 1 To Len(lstr)
		t_=Asc(Mid(lstr, i, 1))
		If t_<97 Or t_>122  Then hu_isLetters = False:Exit Function
	Next
	hu_isLetters = True
End Function
'随机显示字符
Function hu_rndObj(str,pattern)
	str=Split(str,pattern)
	Randomize
	hu_rndObj=str(int(rnd()*(UBound(str)+1)))
End Function
'检查组件是否已经安装
Function hu_isObjInstalled(str)
	Dim xObj
	On Error Resume Next
	hu_isObjInstalled = False
	Err = 0
	Set xObj = Server.CreateObject(str)
	If Err = 0 Or Err = -2147352567 Then hu_isObjInstalled = True
	Set xObj = Nothing
	Err = 0
End Function
'检查是否纯数字
Function hu_isNumeric(str)
	If hu_isNull(str)=False And IsNumeric(str) Then hu_isNumeric=True: Exit Function
	hu_isNumeric=False
End Function
'检查是否纯数字,用于快速检查
Function hu_isNumber(str)
	If str<>"" And IsNumeric(str) Then hu_isNumber=True: Exit Function
	hu_isNumber=False
End Function
%>